home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / comm / urlget09.zip / URLGET.CMD < prev   
OS/2 REXX Batch file  |  1997-04-02  |  4KB  |  158 lines

  1. /*
  2. **                             UrlGet 0.9
  3. **                     copyright 1997 Ed Blackman
  4. **
  5. ** Acknowledgments:
  6. **  Originally by mortenf@login.dknet.dk (Morten Frederiksen)
  7. **  Complete rewrite by edgewood@pobox.com (Ed Blackman)
  8. **
  9. ** Change log:
  10. **  Who:   When:        What was done:
  11. **  EBB    1996/Oct/16  removed requirement of 4OS2
  12. **  EBB    1996/Oct/16  removed use of unnecessary temp files
  13. **  EBB    1996/Nov/05  creates WebEx URL objects instead of writing a text file
  14. **  EBB    1997/Mar/05  added "batch" mode capability
  15. **                      - creates objects for all valid URLs in the input file
  16. **                      - the name of the URL is used as the description: 
  17. **                        the user is not prompted
  18. **  EBB    1997/Mar/31  added install script
  19. **  EBB    1997/Apr/01  added choice of creating Warp 4 URL objects
  20. */
  21.  
  22. arg msgfile
  23.  
  24. if msgfile == "" then
  25.     call usage
  26.  
  27. app='URLCommander'
  28. urlpath=''
  29. mode=''                      
  30. objclass=''
  31. setupstr=''
  32.  
  33. /* Load RexxUtil functions if not already loaded */
  34. if RxFuncQuery('SysLoadFuncs') then do
  35.     say "Loading RexxUtil functions"
  36.     call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  37.     call SysLoadFuncs
  38. end /* do */
  39.  
  40. call readini
  41.  
  42. prefix.0 = 4                            /* URL prefixes to search for */
  43. prefix.1 = 'http://'
  44. prefix.2 = 'https://'
  45. prefix.3 = 'ftp://'
  46. prefix.4 = 'gopher://'
  47.         
  48. do while lines(msgfile)
  49.     msgline=linein(msgfile)
  50.     do i = 1 to prefix.0
  51.         if pos(prefix.i,msgline)>0 then
  52.         do
  53.             urltmp=substr(msgline,pos(prefix.i,msgline))
  54.             goodurl=1
  55.             n=1
  56.             url=''
  57.             do while goodurl
  58.                 ch=substr(urltmp,n,1)
  59.                 if ch=' ' | ch='>' | ch='<' | ch='"' then
  60.                     goodurl=0
  61.                 else
  62.                     url=url||ch
  63.                 n=n+1
  64.             end
  65.  
  66.             if mode = 'INTERACTIVE' then
  67.                 desc = getdesc(url)
  68.             else
  69.                 desc = url
  70.             
  71.             if desc <> '' then
  72.             do
  73.                 title=desc || d2c(10) || date() time()
  74.                 if SysCreateObject(objclass, title, urlpath,,
  75.                         setupstr || url) == 0 then
  76.                     call create_failed
  77.             end
  78.         end
  79.     end i
  80. end
  81.  
  82. exit
  83.  
  84. create_failed:
  85.     call SysQueryClassList 'class.'
  86.     found = 0
  87.     do i = 1 to class.0
  88.         if left(class.i, length(objclass)) = objclass then
  89.             found = 1
  90.     end i
  91.     if \found then
  92.         say objclass 'is not registered.'
  93.     say 'Cannot create object for url' url
  94.     return
  95.  
  96. getdesc: procedure
  97.     parse arg url .
  98.     call charout ,'['||url||']: '
  99.     desc = ''
  100.     key = SysGetKey("noecho")
  101.     do while key \= d2c(13)
  102.         select
  103.             when key = d2c(8) then /* backspace */
  104.             do
  105.                 call erase 1
  106.                 desc = substr(desc, 1, length(desc) - 1)
  107.             end
  108.             when key = d2c(27) then /* escape */
  109.             do
  110.                 call erase length(desc)
  111.                 desc = ''
  112.             end
  113.             otherwise
  114.             do
  115.                 call charout , key
  116.                 desc = desc || key
  117.             end /* do */
  118.         end /* select */
  119.  
  120.         key = SysGetKey("noecho")
  121.     end /* do while */
  122.     say
  123.     return desc
  124.  
  125. readini: 
  126.     inifile = SysIni("USER", app, "IniFile")
  127.     if inifile == "ERROR:" then
  128.     do
  129.         say "Can't find path to .INI file"
  130.         exit
  131.     end
  132.     urlpath = SysIni(inifile, "URLGet", "URLPath")
  133.     mode = SysIni(inifile, "URLGet", "Mode")
  134.     objclass = SysIni(inifile, "URLGet", "ObjectClass")
  135.     setupstr = SysIni(inifile, "URLGet", "SetupString")
  136.  
  137.     concat = urlpath||mode||objclass||setupstr
  138.     if pos("ERROR:", concat) > 0 then
  139.     do
  140.         say "Missing keys in" inifile
  141.         exit
  142.     end
  143.     drop concat inifile
  144. return
  145.  
  146. usage:
  147.     say "Usage: URLGet <file>"
  148.     say "    where <file> is the name of a text file containing URLs"
  149.     exit
  150.     
  151. erase:              /* erase n characters on screen */
  152.     parse arg n
  153.     if n > 0 then
  154.         do i = 1 to n
  155.             call charout , d2c(8) || ' ' || d2c(8)
  156.         end i
  157.     return
  158.